<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%- include ../taglibs/layout_head.ejs%>
    <%- include ../taglibs/layout.css.ejs%>
    <link rel="stylesheet" href="/js/mapPlugins/css/DrawingManager_min.css" type="text/css">
    <link rel="stylesheet" href="/js/mapPlugins/css/SearchInfoWindow_min.css" type="text/css">
    <link rel="stylesheet" href="/loader/fakeLoader.css" type="text/css">
    <link href="js/plugins/zTree/css/metroStyle/metroStyle.css" rel="stylesheet">
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=5pOe9cqol0NaNdEbtvTXMC9h"></script>
    <style type="text/css">
        .baseCommonFence-box{
            position: fixed;
            bottom: 60px;
            right: 10px;
            border:1px solid #e7ecf1;
            border-radius: 4px;
            display: inline-block;
            background-color: #fff;
        }
        .baseCommonFence-box .baseCommonFence-box-head{
            display: block;
            border-bottom: 1px solid #e7ecf1;
        }
        .baseCommonFence-box .baseCommonFence-box-head > span{
            display: inline-block;
            height: 34px;
            line-height: 28px;
            font-size: 14px;
            border-right: 1px solid #e7ecf1;
            padding: 3px 6px;
        }
        .baseCommonFence-box .baseCommonFence-box-button{
            display: block;
            padding: 6px;
            text-align: center;
        }
        .baseCommonFence-box .baseCommonFence-box-button>button{

        }
        .baseCommonFence-box .baseCommonFence-box-search{
            padding: 3px 6px;
        }
        .baseCommonFence-box .baseCommonFence-box-content{
            width: 240px;
            height: 260px;
            padding: 6px 12px;
        }
        #myunBindCarModal .fixed-table-container{
            max-height: 240px!important;
            overflow-y: auto!important;
        }
        #myunBindCarModal .fixed-table-body{
            /*overflow-y: hidden!important;*/
        }
    </style>
    <script type="text/javascript">
        String.prototype.replaceAll = function (reallyDo, replaceWith) {
            return this.replace(new RegExp(reallyDo, ("gm")), replaceWith);
        };
        var parentMenuList = '<%= parentMenuList%>';
        var  sysMap = '<%= sysMap%>';
        var _parentMenuList,
            _sysMap;
        if(parentMenuList !="false"){
            if(parentMenuList.indexOf("&quot;") != -1){
                _parentMenuList = parentMenuList.replaceAll("&quot;", "\"");
            }else if(parentMenuList.indexOf("&#34;") != -1){
                _parentMenuList = parentMenuList.replaceAll("&#34;", "\"");
            }
            window.sessionStorage.setItem("rootMenus",_parentMenuList);
        }
        if(sysMap !="false"){
            if(sysMap.indexOf("&quot;") != -1){
                _sysMap = sysMap.replaceAll("&quot;", "\"");
            }else if(sysMap.indexOf("&#34;") != -1){
                _sysMap = sysMap.replaceAll("&#34;", "\"");
            }
            window.sessionStorage.setItem("chidlMenus",_sysMap)
        }
    </script>
</head>
<body>
<%-include("../taglibs/header.ejs",{params:{className:"active",applyIsActive:"true"}})%>
<div class="nav-body" id="divContent">
    <div class="nav-box">
        <div class="row">
            <div class="col-sm-4 col-md-3 col-lg-2 nav-box-left-box">
                <%-include("appManageLeftMenu.ejs",{params:{className:"active",electronManage:"true"}})%>
            </div>
            <div class="col-sm-6 col-md-9 col-lg-10 right-container-box">
                <div class="right-container">
                    <!--<div class="row">-->
                        <!--<div class="col-sm-12">-->
                            <!--<a class="back-view" id="back-view">-->
                                <!--<i class="fa fa-chevron-left fa-back-left"></i>-->
                                <!--返回-->
                            <!--</a>-->
                        <!--</div>-->
                    <!--</div>-->
                    <section>
                        <div style="height: 100%;width:100%;position:absolute;-webkit-transition: all 0.5s ease-in-out;transition: all 0.5s ease-in-out;">
                            <div id="map" style="height: 100%;-webkit-transition: all 0.5s ease-in-out;transition: all 0.5s ease-in-out;"></div>
                            <div id="app-right-top">
                                <div id="user-center" class="ui3-user-center-wrap">
                                    <div class="avatar-abstract"></div>
                                </div>
                            </div>
                        </div>
                    </section>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="baseCommonFence-box">
    <div class="baseCommonFence-box-head">
        <span>
            电子围栏
        </span>
        <span>
       <button id="bindCar"
               type="button"
               class="btn  btn-theme"
               style="margin-bottom: 3px;padding: 3px 6px;" >绑定车辆</button>
        </span>
        <span>
          <button id="unbindCar"
                  type="button"
                  class="btn btn-danger"
                  style="margin-bottom: 3px;padding: 3px 6px;" >解除绑定</button>
        </span>

    </div>
    <!--<div class="baseCommonFence-box-button">-->
        <!--<button type="button" class="btn btn-primary" onclick="save()">新增电子围栏</button>-->
        <!--<button type="button" class="btn btn-primary" onclick="save()">清除围栏</button>-->
    <!--</div>-->
    <div class="baseCommonFence-box-search" style="position:relative;">
        <input type="text" class="form-control" id="search-name" placeholder="请输入围栏名称">
        <span class="search-img" id="search-icon"
        style="position: absolute;
    /* right: 15px; */
    /* top: 17px; */
    right: 6px;
    top: 10px;
    width: 20px;
    height: 20px;
    cursor: pointer;">
            <img src="images/page3/u1242.png" class="img" style="width: 20px;
    height: 20px;">
        </span>
    </div>
    <div class="baseCommonFence-box-content ">
        <table class="table-responsive" id="electronopenTable" style="min-width: 480px!important;"></table>
    </div>
</div>
<div class="modal inmodal" id="myModal" role="dialog" data-width="500px"
     data-height="400px" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content animated bounceInRight">
            <div class="modal-header">
                <h4 class="modal-title">电子围栏</h4>
            </div>
            <div class="modal-body" style="max-height: 400px; ">

                <form class="form-horizontal m-t" id="editForm" method="get">
                    <input id="id" name="id" type="hidden">
                    <input id="fenceType" name="fenceType" type="hidden">
                    <input id="memo" name="memo" type="hidden">
                    <input id="contentinfo" name="contentinfo" type="hidden">
                    <div class="form-group">
                        <label class="col-sm-3 control-label label-require" style="font-size: 14px;">围栏名称：</label>
                        <div class="col-sm-8">
                            <input id="settingname" name="settingname" class="form-control"
                                   placeholder="名称必填" type="text" aria-required="true"
                                   aria-invalid="true">
                        </div>
                    </div>
                    <div class="form-group" id="editMapWeilan" style="display: none">
                        <label class="col-sm-3 control-label" style="font-size: 14px;"></label>
                        <div class="col-sm-8">
                            <p id="drawWeiLan" style="color: #0ae;font-size: 16px;text-align: center;cursor: pointer">点击关闭窗口进行画围栏</p>
                        </div>
                    </div>
                    <div class="form-group hidden" id="settingname_div">
                        <label class="col-sm-3 control-label" style="font-size: 14px;">预计耗时(分钟)：</label>
                        <div class="col-sm-8">
                            <input id="lineTime" name="lineTime" class="form-control"
                                   placeholder="预计耗时" type="text" number="true" value="25">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">

                <button type="button" class="btn btn-white" onclick="closeModal()">关闭</button>
                <button type="button" class="btn btn-primary" onclick="save()">保存</button>
            </div>
        </div>
    </div>
</div>
<div class="modal inmodal" id="myBindCarModal" role="dialog" data-width="500px"
     data-height="400px" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content animated bounceInRight">
            <div class="modal-header">
                <h4 class="modal-title">绑定车辆</h4>
            </div>
            <div class="modal-body" style="max-height: 400px; ">

                <form class="form-horizontal m-t"  method="get">
                    <!--<input id="id" name="id" type="hidden">-->
                    <!--<input id="fenceType" name="fenceType" type="hidden">-->
                    <!--<input id="memo" name="memo" type="hidden">-->
                    <!--<input id="contentinfo" name="contentinfo" type="hidden">-->
                    <input id="fenceid" name="fenceid" type="hidden">
                    <input id="carid" name="carid" type="hidden">
                    <div class="form-group">
                        <label class="col-sm-3 control-label label-require" style="font-size: 14px;">围栏名称：</label>
                        <div class="col-sm-8">
                            <input id="fenceName" name="fenceName" class="form-control"
                                    type="text"
                                    style="padding-right: 54px">
                            <button type="button" class="btn btn-theme selectWeiLan"
                                    style="position: absolute;top: 0px;right: 15px;">选择</button>
                        </div>
                    </div>
                    <div class="form-group " id="settingname_div">
                        <label class="col-sm-3 control-label label-require" style="font-size: 14px;">选择车辆：</label>
                        <div class="col-sm-8">
                            <input id="carName" name="carName" class="form-control"
                                    type="text" number="true" style="padding-right: 54px">
                            <button type="button" class="btn btn-theme selectCar"
                                    style="position: absolute;top: 0px;right: 15px;">选择</button>
                        </div>
                    </div>
                    <div class="form-group " id="settingname_div1">
                        <label class="col-sm-3 control-label" style="font-size: 14px;">报警类型：</label>
                        <div class="col-sm-8">
                            <select class="form-control m-b" id="isDriverType"
                                    name="isDriverType" type="select">
                                <option value="0">进区域报警</option>
                                <option value="1">出区域报警</option>
                                <option value="2">进出区域报警</option>
                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-white" onclick="closeCarModal()">关闭</button>
                <button type="button" class="btn btn-primary" onclick="saveFence()">保存</button>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="myWeilanTreeDialog" style="z-index: 11000;">
    <div class="modal-dialog" style="width: 320px;">
        <div class="modal-content" style="width: 320px;">
            <div class="modal-header">
                <button type="button" class="close" onclick="closeWerLanDialog()">×</button>
                <h4 class="modal-title" id="NoPermissionModalLabel">围栏数据</h4>
            </div>
            <div class="modal-body" style="height:320px;max-height:320px;max-width: 320px;
                overflow: auto;">
                <div class="input-group div-serch-input" style="margin-bottom: 10px;">
                    <input type="text" placeholder="请录入名称查询" class="input form-control" id="serchStr">
                    <span class="input-group-btn">
                                        <button type="button" class="btn btn btn-primary" onclick="queryFenceTree()"
                                         style="background-color: #48bcb4;border-color: #48bcb4;">
                                            <i class="fa fa-search"></i> 搜索</button>
                                    </span>
                </div>
                <ul id="fenceTree" class="ztree">
                </ul>
            </div>
            <div class="modal-footer">
                <button class="btn btn-info"  type="button" onclick="getAllCheckFenceNodes()">确 定</button>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="myCarTreeDialog" style="z-index: 11000;">
    <div class="modal-dialog" style="width: 320px;">
        <div class="modal-content" style="width: 320px;">
            <div class="modal-header">
                <button type="button" class="close" onclick="closeCarDialog()">×</button>
                <h4 class="modal-title" id="NoPermissionModalLabel">车辆数据</h4>
            </div>
            <div class="modal-body" style="height:320px;max-height:320px;max-width: 320px;
                overflow: auto;">
                <div class="input-group div-serch-input" style="margin-bottom: 10px;">
                    <input type="text" placeholder="请录入名称查询" class="input form-control" id="serchStrCar">
                    <span class="input-group-btn">
                                        <button type="button" class="btn btn btn-primary" onclick="queryMyCarTree()"
                                                style="background-color: #48bcb4;border-color: #48bcb4;">
                                            <i class="fa fa-search"></i> 搜索</button>
                                    </span>
                </div>
                <ul id="kindTree" class="ztree">
                </ul>
            </div>
            <div class="modal-footer">
                <button class="btn btn-info"  type="button" onclick="getAllCheckCarNodes()">确 定</button>
            </div>
        </div>
    </div>
</div>
<div class="modal inmodal" id="myunBindCarModal" role="dialog" data-width="960px"
     data-height="400px" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content animated bounceInRight" style="width: 768px">
            <div class="modal-header">
                <h4 class="modal-title">绑定列表</h4>
            </div>
            <div class="modal-body" style="max-height: 768px; ">
                <form class="form-inline"  method="get">
                    <!--<input id="id" name="id" type="hidden">-->
                    <!--<input id="fenceType" name="fenceType" type="hidden">-->
                    <!--<input id="memo" name="memo" type="hidden">-->
                    <!--<input id="contentinfo" name="contentinfo" type="hidden">-->
                    <input id="fenceid" name="fenceid" type="hidden">
                    <input id="carid" name="carid" type="hidden">
                    <div class="form-group">
                        <label style="font-size: 14px;">围栏名称：</label>
                        <div style="position: relative;display: inline-block">
                            <input id="fenceCode" name="code" class="form-control"
                                   type="text"
                                   style="padding-right: 54px;width: 130px">
                            <button type="button" class="btn btn-theme selectWeiLan"
                                    style="position: absolute;top: 0px;right: 0px;">选择</button>
                        </div>
                    </div>
                    <div class="form-group" id="settingname_div">
                        <label  style="font-size: 14px;">选择车辆：</label>
                        <div style="position: relative;display: inline-block">
                            <input id="baseCarName" name="baseCarName" class="form-control"
                                   type="text" number="true" style="padding-right: 54px;width: 130px">
                            <button type="button" class="btn btn-theme selectCar"
                                    style="position: absolute;top: 0px;right: 0px;">选择</button>
                        </div>
                    </div>
                    <div class="form-group" id="settingname_div1">
                        <label  style="font-size: 14px;">报警类型：</label>
                        <div style="position: relative;display: inline-block">
                            <select class="form-control m-b" id="_isDriverType"
                                    name="_isDriverType" type="select">
                                <option value="0">进区域报警</option>
                                <option value="1">出区域报警</option>
                                <option value="2">进出区域报警</option>
                            </select>
                        </div>
                    </div>
                    <button type="button" class="btn btn-round btn-theme" id="dosearch" style="margin-bottom: 3px;margin-top: 3px">查 询</button>
                    <button type="button" class="btn btn-round btn-danger" id="reset" style="margin-bottom: 3px;margin-top: 3px">重 置</button>
                </form>
                <table class="table-responsive" id="bindCarTable"></table>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-white" onclick="closeBindListModal()">关闭</button>
                <!--<button type="button" class="btn btn-primary" onclick="saveFence()">保存</button>-->
            </div>
        </div>
    </div>
</div>
<%-include ../taglibs/layout.js.ejs%>
<script src="/js/plugins/zTree/js/jquery.ztree.all-3.5.js"></script>
<script src="/js/plugins/zTree/js/jquery.ztree.exhide-3.5.js"></script>
<!--<script src="/js/ztree/ztree-cus-table.js"></script>-->
<script src="/js/ztree/ztree-cus-map.js"></script>
<script src="/js/ztree/ztree-user.js"></script>
<script type="text/javascript" src="/js/mapPlugins/DrawingManager.js"></script>
<script type="text/javascript" src="/js/mapPlugins/SearchInfoWindow_min.js"></script>
<script type="text/javascript" src="/js/mapPlugins/MapUtil.js"></script>
<script type="text/javascript" src="/js/mapPlugins/angle.js"></script>
<script type="text/javascript" src="js/viewpage/applactionManage/applactionManage.js"></script>
<script type="text/javascript" src="js/viewpage/dataManage/userInfo/userInfo.js"></script>
<script type="text/javascript">
    var electronopenTable;
    var bindCarTable;
    var isUnbinCar = false;
    $(function () {
        UserInfo.initEditUserPage();
        electronopenTable = new BootstrapTable($('#electronopenTable'),{
            url:"/electronManage/queryFenceList",
            pagination:false,
            singleSelect:false,
            height:240,
            onClickRow:function (row, $element,field) {
                edit(row);
            },
            columns: [{
                field:"settingname",
                title:"围栏名称"
            },{
                field:"fenceType",
                title:"围栏类型",
                formatter:function (value,data,index) {
                    var d = data;
                    //e是得到的json数组中的一个item ，可以用于控制标签的属性。
                    var ftype = d.fenceType;
                    var stype="";
                    if(ftype=="1"){
                        stype = "兴趣点";
                    }else if(ftype=="2"){
                        stype = "区域圆形";
                    }else if(ftype=="3"){
                        stype = "区域多边形";
                    }else if(ftype=="4"){
                        stype = "路线折线";
                    }
                    return stype
                }
            },
                {
                    field: 'lineTime',
                    title: '预计耗时'
                }, {
                    field: 'lineDis',
                    title: '里程'
                },
                {
                    field: 'id',
                    title: '操作',
                    width:120,
                    formatter:function (value,row,index) {
                        return "<button type=\"button\" class=\"btn  btn-theme\" style=\"margin-bottom: 3px;margin-top: 3px;margin-right: 3px;padding: 3px 6px;\" onclick='editFence("+row.id+")'>修 改</button><button type=\"button\" class=\"btn btn-danger\"  style=\"margin-bottom: 3px;margin-top: 3px;padding: 3px 6px;margin-right: 3px;\" onclick='deleteFence("+row.id+")'>删 除</button>"
                    }
                }

            ]

        });
        electronopenTable.init();
        bindCarTable = new BootstrapTable($('#bindCarTable'),{
            url:"/electronManage/list",
            pagination:false,
            singleSelect:false,
            height:240,
            columns: [{
                field:"settingname",
                title:"围栏名称"
            },{
                field:"baseCarNo",
                title:"车牌号",
            },
                {
                    field: 'isDriverType',
                    title: '报警类型',
                    formatter:function (value,data,index) {
                        var d = data;
                        //e是得到的json数组中的一个item ，可以用于控制标签的属性。
                        //0-驶入报警 1-驶出报警 2-驶入驶出报警 3-偏离报警

                        var stype="";
                        if(value=="0"){
                            stype = "进区域报警";
                        }else if(value=="1"){
                            stype = "出区域报警";
                        }else if(value=="2"){
                            stype = "进出区域报警";
                        }
                        return stype
                    }
                },
                {
                    field: 'id',
                    title: '操作',
                    formatter:function (value,row,index) {
                        return "<button type=\"button\" class=\"btn btn-danger\"  style=\"margin-bottom: 3px;margin-top: 3px;padding: 3px 6px;margin-right: 3px;\" onclick='unbindCarFence("+row.id+")'>解除绑定</button>"
                    }
                }

            ]

        });
        bindCarTable.init();
        $("#bindCar").on("click",function () {
            $("#myBindCarModal").show();
        });
        $("#unbindCar").on("click",function () {
            $("#myunBindCarModal").show();
            isUnbinCar = true;
        });

        $("#search-icon").click(function () {
            electronopenTable.refresh({
                query:{
                    settingname:$("#search-name").val()
                }
            })
        })
        $("#dosearch").click(function () {
            bindCarTable.refresh({
                query:{
                    code:$("#fenceCode").val(),
                    baseCarNo:$("#baseCarName").val(),
                    isDriverType:$("#_isDriverType").val()
                }
            })
        })
        $("#reset").click(function () {
            $("#fenceCode").val("");
            $("#baseCarName").val("");
            $("#_isDriverType").val("")
        })
        $('#myModal').on('hidden.bs.modal', function (e) {
            closeModal();
        });
        $("#drawWeiLan").click(function () {
            $("#myModal").modal("hide");
        })
    })
    
    function closeCarModal() {
        $("#myBindCarModal").hide();
    }
    function closeBindListModal() {
        isUnbinCar= false;
        $("#myunBindCarModal").hide();
    }
    function unbindCarFence(id) {
        if (id) {
            del(id);
        } else {
            swal("系统提示", "请选择需要解除绑定的数据！", "warning");
        }
    }
    function del(id) {
        swal({
                title: "您确定要解除绑定吗",
                text: "解除绑定后将无法恢复，请谨慎操作！",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "是的，我要解除绑定！",
                cancelButtonText: "让我再考虑一下…",
                closeOnConfirm: false,
                closeOnCancel: false
            },
            function (isConfirm) {
                if (isConfirm) {
                    $.ajax({
                        type: "GET",
                        url: "/baseFenceManager/del",
                        cache: false,
                        async: false,
                        data: {
                            ids: id
                        },
                        dataType: "json",
                        success: function (data) {
//                            swal("删除成功！", "您已经永久删除了这条信息。", "success");
                            swal("解除绑定成功！", "解除绑定成功！", "success");
                            //query();
                            bindCarTable.refresh();
                        }
                    });

                } else {
                    swal("已取消", "您取消了解除绑定操作！", "error");
                }
            });
    }
</script>
<!--map-->
<script type="text/javascript">
    // 百度地图API功能
    var map;
    var carIocnPath="/js/mapPlugins/img/";
    var lastMark=[];
    var lastCarMark={};//终端数组
    var drawingManager;
    var local;
    var opts = {
        width : 200,     // 信息窗口宽度
        height: 330,     // 信息窗口高度
//        title : "实时信息" , // 信息窗口标题
        panel  : "panel",
        enableMessage:true,//设置允许信息窗发送短息
        searchTypes   :[
            BMAPLIB_TAB_SEARCH,   //周边检索
            BMAPLIB_TAB_TO_HERE,  //到这里去
            BMAPLIB_TAB_FROM_HERE //从这里出发
        ]
    };
    //    var carIcon="car_online0.fw";
    var url='/tree/deptCar';
    var fenceUrl='/tree/fences';
    $(function () {
        map = new BMap.Map('map');
        map.addControl(new BMap.NavigationControl());
        map.addControl(new BMap.ScaleControl());
        map.addControl(new BMap.OverviewMapControl());
        map.enableScrollWheelZoom();
//        map.addControl(new BMap.MapTypeControl());
        var contextMenu =settxtMenuItem(new BMap.ContextMenu());
        map.addContextMenu(contextMenu);
        local = new BMap.LocalSearch(map, {
            renderOptions:{map: map}
        });
        initPoint();
        drawingManager=initDrawingManager();
    });
    function addFence(str,flag,memo) {
        $("#myModal").modal("show");
        $("#contentinfo").val(str);
        $("#fenceType").val(flag);
        $("#memo").val(memo);
        $("#lineTime").val(0);
        if(flag=="4"){
            $("#settingname_div").removeClass('hidden').addClass('show');
        }else{
            $("#settingname_div").removeClass('show').addClass('hidden');
        }
        clearAlldrawingModes();
    }
    function closeModal() {
        //$("#myModal").setDefForm(validator);
        $("#myModal").modal("hide");
        $("#editMapWeilan").hide();
        clearAlldrawingModes();
    }
    function save() {
        $('#editForm').ajaxSubmit({
            type: 'post', // 提交方式 get/post
            dataType: 'json',
            url: '/baseCommonFence/save', // 需要提交的 url
            beforeSubmit: function (formData, jqForm, options) {
//                if (!$("#editForm").valid()) {
//                    return false;
//                }
                if($("#settingname").val()==""){
                    $.messageExt.alert("系统提示","围栏名称是必填项！","warning");
                    return false
                }
            },
            success: function (data) {
                // data 保存提交后返回的数据，一般为 json 数据
                // 此处可对 data 作相关处理
                if (data.success) {
                    swal({
                        title: "系统提示",
                        text: data.msg,
                        type: "success"
                    });
                   // $("#myModal").setDefForm(validator);
                    $('#editForm').clearForm(true);
                    $("#myModal").modal("hide");
                    electronopenTable.refresh();
                    //query();
                    $("#editMapWeilan").hide();
                    loadMyTree(fenceUrl,"fenceTree",true);
                } else {
                    swal({
                        title: "系统提示",
                        text: data.msg,
                        type: "error"
                    });
                }
                clearAlldrawingModes();
            },

        });
    }


    $(function () {

//        init_tree('id','parentId','name',fnClickCar,fntreeCheck,"radio");
//        loadMyTree(url,"kindTree",true);
        UserTreeComponents.initUserTree('id', 'parentId', 'name',fnClickCar,fntreeCheck, "radio");
        UserTreeComponents.loadUserTree(url,"kindTree",true);
        init_tree('id','parentId','name',fnClickFence,treeCheck,"radio");
        loadMyTree(fenceUrl,"fenceTree",true);
        $(".selectWeiLan").click(function () {
            $("#myWeilanTreeDialog").modal("show");
        })
        $(".selectCar").click(function () {
            $("#myCarTreeDialog").modal("show");
        })
    });
    function queryFenceTree() {
        var str = $("#serchStr").val();
        if(str){
            search_ztree("fenceTree","serchStr")
        }else{
            loadMyTree(fenceUrl,"fenceTree",true);
        }
    }

    function queryMyCarTree() {
        var str = $("#serchStrCar").val();
        if(str){
            UserTreeComponents.searchZtree("kindTree","serchStrCar")
        }else{
            UserTreeComponents.loadUserTree(url,"kindTree",true);
        }
    }
//    function queryCarTree() {
//        var str = $("#serchStr").val();
//        if(str){
//            search_ztree("fenceTree","serchStr")
//        }else{
//            loadMyTree(fenceUrl,"fenceTree",true);
//        }
//    }
    //    树节点选中
    var fnClickCar=function (event, treeId, treeNode) {
        if(treeNode.isCar){
            $("#h_car_id").val(treeNode.id);
            $("#h_car_no").val(treeNode.name);
            var fenceType=treeNode.type;
            var contentinfo=treeNode.jw;
            var memo=treeNode.memo;
            //drawingFence(fenceType,contentinfo);
        }else{
            $("#h_car_id").val("");
            $("#h_car_no").val("");
        }


    }
    var fnClickFence=function (event, treeId, treeNode) {
        if(treeNode.isLeaf){
            $("#h_fence_id").val(treeNode.id);
            $("#h_fence_name").val(treeNode.name);
            debugger;
            showFence(treeNode.type,treeNode.jw,treeNode.memo);
        }


    }

    function fntreeCheck(event, treeId, treeNode, clickFlag) {

    }
    function treeCheck(event, treeId, treeNode, clickFlag) {

    }
    function closeWerLanDialog() {
        $("#myWeilanTreeDialog").modal("hide");
    }
    function closeCarDialog() {
        $("#myCarTreeDialog").modal("hide");
    }
    function getAllCheckCarNodes() {
        var node = userTreeObj.getCheckedNodes(true)[0];
        if(node){
            if(isUnbinCar){
                $("#baseCarName").val(node.name);
            }else{
                $("#carName").val(node.name);
                $("#carid").val(node.id);
            }

            //$("#deptTwoId").val(node.id);
        }else{
            if(isUnbinCar){
                $("#baseCarName").val("");
            }else{
                $("#carName").val("");
                $("#carid").val("");
            }
        }
        closeCarDialog();
    }
    function getAllCheckFenceNodes() {
        var node = zTree_obj.getCheckedNodes(true)[0];
        if(node){
            if(isUnbinCar){
                $("#fenceCode").val(node.name);
            }else{
                $("#fenceName").val(node.name);
                $("#fenceid").val(node.id);
            }

            //$("#deptTwoId").val(node.id);
        }else{
            if(isUnbinCar){
                $("#fenceCode").val("");
            }else{
                $("#fenceName").val("");
                $("#fenceid").val("");
            }
        }
        closeWerLanDialog();
    }
    function saveFence() {
        if($("#fenceid").val() == ""){
            $.messageExt.alert("系统提示","围栏名称是必填项！","warning")
            return false
        }
        if($("#carid").val() == ""){
            $.messageExt.alert("系统提示","车辆是必填项！","warning")
            return false
        }
        var jsonstr = [];
        var row={
            "carid":$("#carid").val(),
            "fenceid":$("#fenceid").val(),
            "isDriverType":$("#isDriverType").val(),
        };
        jsonstr.push(row);
        $.ajax({
            type: "post",
            url: "/baseFenceManager/save",
            cache: false,
            async: true,
            data: {
                jsonstr: JSON.stringify(jsonstr)
            },
            dataType: "json",
            success: function (data) {
                if (data.success) {
                    swal({
                        title: "系统提示",
                        text: data.msg,
                        type: "success"
                    });
                    //刷新下方列表数据，清空绑定列表数据
//                    tableFenceTem.DataTable().rows().remove().draw( false );
//                    query();
                    bindCarTable.refresh();
                } else {
                    swal({
                        title: "系统提示",
                        text: data.msg,
                        type: "error"
                    });
                }
            }
        });
    }
    
    function editFence(id) {
        $.ajax({
            type: "GET",
            url: "/baseCommonFence/edit",
            cache: false,
            async: true,
            data: {
                id: id
            },
            dataType: "json",
            success: function (data) {
//                            swal("删除成功！", "您已经永久删除了这条信息。", "success");
                //swal("删除成功！", data, "success");
                //query();
                //electronopenTable.refresh();
                if(data){
                    for(var k in data){
                        $("#editForm").find("input[name='"+k+"']").val(data[k]);
                    }
                }
                $("#editMapWeilan").show();

                edit(data);
                $("#myModal").modal("show");
            }
        });
    }

    function edit(data) {
        clearAlldrawingModes();
        //var data = table.DataTable().rows(index).data()
        if (data) {
            //loadComb("baseCarNoColour",combColor);
//            $('#editForm').resetForm();
            var contentinfo=data.contentinfo;
            var memo=data.memo;
            var fenceType=data.fenceType;
            if(fenceType && fenceType==1 && contentinfo){
                var array=contentinfo.split(",")
                addDrawingMark(array[0], array[1]);
            }else if(fenceType && fenceType==2 && contentinfo){
                var radius=contentinfo.split(";")[1];
                var array=contentinfo.split(";")[0].split(",")
                addDrawingCircle(array[0], array[1],radius);
            }else if(fenceType && fenceType==3 && contentinfo){
                var points=contentinfo.split(";");
                var array=memo.split(",")
                addDrawingPolygon(points,array[0],array[1]);
            }else if(fenceType && fenceType==4 && contentinfo){
                var points=contentinfo.split(";");
                var array=memo.split(",")
                addDrawingPolyline(points,array[0],array[1]);
            }

        } else {
            swal("已取消", "数据错误！", "warning");
        }
    }

    function deleteFence(id) {
        $.ajax({
            type: "GET",
            url: "/baseCommonFence/del",
            cache: false,
            async: true,
            data: {
                ids: id
            },
            dataType: "json",
            success: function (data) {
//                            swal("删除成功！", "您已经永久删除了这条信息。", "success");
                swal("删除成功！", data, "success");
                //query();
                electronopenTable.refresh();
                loadMyTree(fenceUrl,"fenceTree",true);
            }
        });

    }


</script>
</body>
</html>